package com.cx.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @author cxx
 * @create 2020-10-28 17:58
 **/
public class Test {


    public static void main(String[] args) {
//     泛型擦除了,为什么还能获取到类的泛型。
//        A:泛型会被保存起来
        ArrayList<String> arrayString=new ArrayList<String>();
        arrayString.add ("1");
        ArrayList<Integer> arrayInteger=new ArrayList<Integer>();
        System.out.println(arrayString.getClass());
        System.out.println(arrayInteger.getClass());
        System.out.println(arrayString.getClass() == arrayInteger.getClass());
        System.out.println ("====================");
        Map<String,String> map1 = new HashMap<> ();
        map1.put ("1","1");
        Map<String,Object> map2 = new HashMap<> ();
        map2.put ("1","1");
        System.out.println (map1.getClass () == map2.getClass ());
        System.out.println (map1.equals (map2));
    }

    public static void main1(String[] args) {
        User user = new User ();
        user.setName ("ctm");
        Utils.print (user,User::getName);
        Utils.test (user,t->"ctm".equals (t.getName ()));
        Utils.consumer (user,t ->{
            System.out.println (t.getName ());
        });
        Utils.supplier (user::getName);
        Utils.supplier (()-> "aaa");


    }


}

class Utils{

    public static <T> void test(T t,Predicate<T> predicate){
        System.out.println (predicate.test (t));
    }

    public static <T,R> void print(T t,Function<T,R> function){
        System.out.println (function.getClass());
        System.out.println (function.apply (t));
    }

    public static <T> void consumer(T t,Consumer<T> consumer){
        consumer.accept (t);
    }

    public static <T> void supplier(Supplier<T> supplier){
        System.out.println ("print::"+supplier.get ());
    }

}

class User{

    private String name;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}